package cn.cuilan.test.it.api;

import cn.cuilan.entity.BookClassify;
import cn.cuilan.repository.BookClassifyRepository;
import cn.cuilan.test.common.CommonTest;
import cn.cuilan.utils.Results;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import static org.junit.Assert.assertTrue;

/**
 * 书籍分类集成测试
 *
 * @author zhang.yue
 * @author zhang.yan
 */
public class BookClassifyControllerIT extends CommonTest {

    /**
     * 接口URL前缀
     */
    private final static String URL_PREFX = "/bookclassify";

    @Autowired
    private BookClassifyRepository bookClassifyRepository;

    @Before
    public void before() {
        BookClassify bookClassify0 = new BookClassify();
        bookClassify0.setClassifyName("娱乐趣事");

        BookClassify bookClassify1 = new BookClassify();
        bookClassify1.setClassifyName("时事政治");

        BookClassify bookClassify2 = new BookClassify();
        bookClassify2.setClassifyName("人文地理");

        bookClassifyRepository.save(bookClassify0);
        bookClassifyRepository.save(bookClassify1);
        bookClassifyRepository.save(bookClassify2);
    }

    @Test
    public void findByClassifyNameLikeIT() {
        // 1. 测试无参请求
        assertTrue(isSuccess(
                testRestTemplate.getForObject(URL_PREFX + "/findAll", Results.class)));

        // 2. 测试有参请求
        assertTrue(isSuccess(
                testRestTemplate.getForObject(URL_PREFX + "/findAll?classifyName=人", Results.class)));
    }

}
